import GChild from "../../../Core/GView/GChild";
import { ITEM_TYPE } from "../../Common/Define";
import { Res } from "../../Common/UIResources";
const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Home/RecuitCardItem')

export default class RecuitCardItem extends GChild {
    private _index: number = 0;
    private _award: Array<number> = [];
    private _cb: Function = null;
    private _scale: number = null;
    @property({ type: cc.Sprite, tooltip: "招募单张卡英雄图片" }) onceHeroCard: cc.Sprite = null;
    @property({ type: cc.Sprite, tooltip: "招募单张卡英雄图片光" }) heroLight: cc.Sprite = null;
    onGLoad() {
        // this.skeInit();
        // GCtrl.ES.on(CMsg.client.home.onRecruit, this, this.onRecruit.bind(this), PRIORITY_VIEW);
    }

    public init(index: number, award: Array<number>, cb?: Function) {
        this._index = index;
        this._award = award;
        this._scale = this.node.scaleX;
        cc.tween(this.node)
            .to(0.38, { scaleX: 0 })//初始位置
            .call(() => {
                this.onceHeroCard.node.children[0].active = this._award[1] == ITEM_TYPE.HERO ? false : true;
                this.heroLight.node.active = this._award[1] == ITEM_TYPE.HERO ? true : false;
                this.assetImpl.spriteFrame(this.onceHeroCard, Res.texture.hero.hero + 'recruit_' + this._award[0]);
            })
            .to(0.38, { scaleX: this._scale })//初始位置
            .union()
            .call(() => {
                this.scheduleOnce(() => {
                    if (cb) {
                        this._cb();
                    }
                }, 1)
            })
            .start()
        if (cb) {
            this._cb = cb;
        }
    }

    // /**初始化 */
    // public skeInit() {
    //     this.skeleton.setEventListener((track: sp.spine.TrackEntry, event: sp.spine.Event) => {
    //         this.onSkEventListen(this.skeleton, track, event);
    //     });
    // }

    // onRecruit() {
    //     this.skeleton.setAnimation(0, "animation", false);
    // }

    // // 骨骼帧事件
    // public onSkEventListen(skeleton: sp.Skeleton, track: sp.spine.TrackEntry, event: sp.spine.Event) {
    //     let eventName = event.data.name;
    //     if (eventName == 'aa') {
    //         console.log("更换卡牌图片");

    //         this.onceHeroCard.node.children[0].active = this._award[1] == ITEM_TYPE.HERO ? false : true;
    //         this.assetImpl.spriteFrame(this.onceHeroCard, Res.texture.hero.hero + 'recruit_' + this._award[0]);
    //         if (this._cb) {
    //             this.scheduleOnce(() => {
    //                 this._cb();
    //             }, 1)
    //         }
    //     }
    // }
}